package com.qdu.commons;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private static final int OK_CODE = 200;
    private static final int FAIL_CODE = 500;
    private static final String OK_MSG = "OK";
    private static final String FAIL_MSG = "FAIL";
    public static final int NO_AUTH_CODE=999;
    public static final String NO_TOKEN="没有认证信息";
    public static final String TOKEN_EXPIRE="TOKEN过期";
    public static final String NO_AUTH_MSG="无访问权限";



    private int code;
    private String msg;
    private T data;

    public static <T> Result<T> success(T data){
        return new Result<>(OK_CODE,OK_MSG,data);
    }

    public static <T> Result<T> failed(String msg){
        return new Result<>(FAIL_CODE,msg,null);
    }

    public static <T> Result<T> noAuth(String msg){
        if(StringUtils.isNotEmpty(msg)){
            return new Result(NO_AUTH_CODE, msg,"FAIL");
        }
        return new Result(NO_AUTH_CODE, NO_AUTH_MSG,"FAIL");
    }
}
